
#include <iostream>
#include <thread>
#include <future>
#include "ThreadPool.h"

std::mutex mut;
int func(int x) {
    auto now = time(nullptr);
    auto dateTime = localtime(&now);
    mut.lock(); // 为了防止打印错乱，我们在这里加锁
    std::cout << "task id: " << x << " thread PID: " << std::this_thread::get_id()
        << " Time: " << dateTime->tm_min << ":" << dateTime->tm_sec << std::endl;
    mut.unlock();
    std::this_thread::sleep_for(std::chrono::seconds(2));
    return x;
}

int main()
{
    ThreadPool threadPool;
    for (int i = 0; i < 20; ++i)
    {
        auto ret = threadPool.commit(func, i);
    }
    std::this_thread::sleep_for(std::chrono::seconds(20));
}
